define(function(require, exports){
	var $ = require("jquery")
		,pubjs = require("pubjs")
		,view = require('@base/view')
		// ,form = require("form")
		// ,popwin = require('popwin')
		// ,common = require("common")
		// ,grid = require("grid")
		,util = require('util');

	// 该方法取得子数组的补集
	// 第一个参数为父数组，第二个参数为子数组
	// 考虑将该方法添加到util
	function _complementArray(fatherArray, subArray) {
		return fatherArray.filter(function(e) {
			return subArray.indexOf(e) < 0;
		})
	}

	/**
	 * 多级选择控件
	 */
	var SubLevelCheckbox = view.container.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'class': 'M-commonNewSLC',
				'readonly': false,
				'selected': null,
				'getSubs': false,
				'callback': null,
				// 子级对应的key
				"key":"children",
				// 层级值对应的key
				"valueKey":"BdxId",
				// 显示名称对应的key
				"nameKey":"Name",
				// 是否发消息
				"silence":true,
				"level":2
			});

			this.Super('init', arguments);

			this.$guid = util.guid('c_');
			this.$list = null;
			this.$selected = this.getConfig().selected;
			this.$key = this.getConfig().key;
			this.$vKey = this.getConfig().valueKey;
			this.$nKey = this.getConfig().nameKey;
		},
		afterBuild: function(){
			var self = this;
			var el = self.getDOM();
			var c = self.getConfig();

			var doms = self.$doms = {};
			doms.head = $('<ul class="M-commonNewSLCHead" />').appendTo(el);
			doms.body = $('<div class="M-commonNewSLCBody" />').appendTo(el);

			doms.head.append('<span>' + LANG('数据加载中...') + '</span>');

			// 绑定事件
			self.uiProxy(doms.head, 'li', 'click', 'eventSwitchSection');
			self.uiProxy(doms.head, 'li > input', 'change', 'eventToggleSection');

			if(util.isMobile()){
				self.uiProxy(doms.body, '.hasSub', 'tap', 'eventHoverItem');
			}else{
				self.uiProxy(doms.body, '.hasSub', 'mouseenter mouseleave', 'eventHoverItem');
			}
			if (!c.readonly){
				self.uiProxy(doms.body, 'input', 'change', 'eventToggleChange');
			}

			if(util.isMobile()){
				self.uiBind(el, 'tap', function(ev){
					self.$timeStamp = ev.timeStamp;
				});

				self.uiBind(document, 'tap', function(ev){
					if(ev.timeStamp !== self.$timeStamp){
						el.find('.hasSub').removeClass('act');
					}
				});
			}
		},
		/**
		 * 设置选项列表
		 * @param {Array} list 列表对象
		 */
		setList: function(list){
			this.$list = list;
			this.buildUI();
		},
		/**
		 * 构建模块界面, 生成选项
		 * @return {None}
		 */
		buildUI: function(){
			var self = this;
			var doms = self.$doms;
			var list = self.$list;
			var c = self.getConfig();
			doms.head.empty();
			doms.body.empty();

			for (var i=0; i<list.length; i++){
				var id = self.$guid + '_' + i;
				self.buildSection(id, list[i]);
			}

			// 显示默认面板
			doms.head.children(':eq(0)').addClass('act');
			doms.body.children(':gt(0)').hide();

			if (c.readonly){
				doms.head.find('input:checkbox').prop('disabled', true);
				doms.body.find('input:checkbox').prop('disabled', true);
			}

			// 设置选中的选项
			if (self.$selected){
				self.setData(self.$selected);
			}

			// 回调函数
			var callback = c.callback;
			if (callback && $.isFunction(callback)) {
				callback.call(self);
			}
		},
		eventToggleChange: function(evt, elm){
			var type = $(elm).attr('data-type');
			switch (type){
				case 'zone':
					this.eventToggleZone(evt, elm);
				break;
				case 'item':
					this.eventToggleItem(evt, elm);
				break;
				case 'sub':
					this.eventToggleSub(evt, elm);
				break;
				case 'subNext':
					this.eventToggleSubNext(evt, elm);
				break;
			}
			if(!this.getConfig().silence){
				// 非静默模式
				this.fire(
					"subLevelChange"
					,{
						"type":type
						,"data":this.getData()
					}
				);
			}
		},
		// 创建分区
		buildSection: function(id, data){
			var self = this;
			var doms = self.$doms;
			var head = $('<li/>').attr('data-link', id).appendTo(doms.head);
			var body = $('<div/>').attr('data-link', id).appendTo(doms.body);

			$('<input type="checkbox"/>').val(data[self.$vKey] === 0 && '0' || data[self.$vKey] || '').appendTo(head);
			$('<label/>').attr('title', LANG(data[self.$nKey])).text(LANG(data[self.$nKey])).appendTo(head);
			var tmp = data[self.$key];
			if(tmp){
				for (var i=0; i<tmp.length; i++){
					var con = $('<div class="M-commonNewSLCZone"/>').toggleClass('alt', (i%2 === 0)).appendTo(body);
					self.buildZone(id + '_' + i, con,tmp[i]);
				}
			}
			tmp = null;
		},
		eventSwitchSection: function(evt, elm){
			elm = $(elm);
			elm.siblings().removeClass('act');
			var link = elm.addClass('act').attr('data-link');
			this.$doms.body.children().hide().filter('[data-link="'+link+'"]').show();
		},
		eventToggleSection: function(evt, elm){
			var dom = $(elm);
			var chk = dom.prop('checked');
			var link = dom.parent().attr('data-link');
			var body = this.$doms.body.children('[data-link="'+link+'"]');
			body.find('input').prop('checked', chk);
			body.find('.M-commonNewSLCSubCount').hide();
			if(!this.getConfig().silence){
				// 非静默模式
				this.fire(
					"subLevelChange"
					,{
						"type":"all"
						,"data":this.getData()
					}
				);
			}
		},
		updateSectionCheck: function(body){
			var input = body.find('input');
			var check = input.filter(':checked').length;
			var link = body.attr('data-link');
			var dom = this.$doms.head.find('[data-link="'+link+'"] > input');
			dom.prop('checked', (input.length > 0 && check == input.length));
		},
		// 创建栏目
		buildZone: function(id, con, data){
			var head = $('<div class="M-commonNewSLCZoneHead" />').appendTo(con);
			$('<input id="'+id+'" type="checkbox" data-type="zone"/>').val(data[this.$vKey] === 0 && '0' || data[this.$vKey] || '').appendTo(head);
			$('<label for="'+id+'"/>').attr('title', LANG(data[this.$nKey])).text(LANG(data[this.$nKey])).appendTo(head);
			var tmp = data[this.$key];
			if (!tmp || !tmp.length){
				return;
			}
			var body = $('<ul class="M-commonNewSLCZoneBody" />').appendTo(con);
			for (var i=0; i<tmp.length; i++){
				var item = $('<li class="M-commonNewSLCItem"/>').appendTo(body);
				this.buildItem(id + '_' + i, item,tmp[i]);
			}
			body.append('<div class="clear"/>');

			// 同步高度
			head.css({
				// 'height': body.height()
			});

			tmp = null;
		},
		eventToggleZone: function(evt, elm){
			var dom = $(elm);
			var chk = dom.prop('checked');
			dom = dom.parent().next();
			if (dom.length){
				dom.find('input').prop('checked', chk);
				dom.find('.M-commonNewSLCSubCount').hide();
			}else {
				dom = $(elm).parent();
			}
			this.updateSectionCheck(dom.parent().parent());
		},
		updateZoneCheck: function(body){
			var input = body.find('input');
			var check = input.filter(':checked').length;
			body.prev().children('input').prop('checked', (input.length > 0 && check == input.length));
			this.updateSectionCheck(body.parent().parent());
		},

		// 创建项目
		buildItem: function(id, con, data){
			var self = this;
			var doms = self.$doms;

			var head = con, body = null
				,tmp = data[self.$key];
			if (tmp && tmp.length){
				head = $('<div class="M-commonNewSLCItemHead" />').appendTo(con).addClass('text-truncate');
				body = $('<ul class="M-commonNewSLCSub" />').appendTo(con).width(doms.body.show().width());
				// doms.body.hide();
				$('<span class="M-commonNewSLCSubCount" />').appendTo(con);
				$('<em class="M-commonNewSLCSubTriangle"/>').appendTo(con);
				con.addClass('hasSub');
			}

			$('<input id="'+id+'" type="checkbox" data-type="item"/>').val(data[self.$vKey] === 0 && '0' || data[self.$vKey] || '').appendTo(head);
			$('<label for="'+id+'"/>').attr('title', LANG(data[self.$nKey])).text(LANG(data[self.$nKey])).appendTo(head);

			if (body){
				for (var i=0; i<tmp.length; i++){
					var item = $('<li/>').appendTo(body);
					self.buildSubItem(id + '_' + i, item, tmp[i]);
				}
			} else {
				con.addClass('text-truncate');
			}
			tmp = null;
		},
		eventHoverItem: function(evt, elm){
			var dom = $(elm);
			var offset = util.offset(this.getDOM(), dom);
			if (evt.type == 'mouseenter' || evt.type == 'tap'){
				dom = dom.children('.M-commonNewSLCItemHead');
				if (dom.length){
					dom.parent().addClass('act');
					dom.next().css({
						'left': offset.left + 1,
						'top': dom.height()
					});
				}

			}else {
				dom.removeClass('act');
			}
		},
		eventToggleItem: function(evt, elm){
			var dom = $(elm);
			if (dom.parent().hasClass('M-commonNewSLCItemHead')){
				var chk = dom.prop('checked');
				dom = dom.parent().next();
				dom.find('input').prop('checked', chk);
				dom.next().hide();
				this.updateCount(dom.parent().parent().find('.M-commonNewSLCSubCount:visible').siblings('.M-commonNewSLCSub').find('li>input').eq(0));
			}
			this.updateZoneCheck(dom.parent().parent());
		},
		// 创建子项目
		buildSubItem: function(id, con, data){
			var self = this;
			var doms = self.$doms;

			var head = con, body = null
				,tmp = data[self.$key];
			if (tmp && tmp.length){
				head = $('<div class="M-commonNewSLCItemHead" />').appendTo(con).addClass('text-truncate');
				body = $('<ul class="M-commonNewSLCSub" />').appendTo(con).width(doms.body.show().width());
				// doms.body.hide();
				$('<span class="M-commonNewSLCSubCount" />').appendTo(con);
				$('<em class="M-commonNewSLCSubTriangle"/>').appendTo(con);
				con.addClass('hasSub');
			}

			$('<input id="'+id+'" type="checkbox" data-type="sub"/>').val(data[self.$vKey] === 0 && '0' || data[self.$vKey] || '').appendTo(head);
			$('<label for="'+id+'"/>').attr('title', LANG(data[self.$nKey])).text(LANG(data[self.$nKey])).appendTo(head);

			if (body){
				for (var i=0; i<tmp.length; i++){
					var item = $('<li/>').appendTo(body);
					self.buildSubNextItem(id + '_' + i, item, tmp[i]);
				}
			} else {
				con.addClass('text-truncate');
			}
			tmp = null;
		},
		// 创建子子项目
		buildSubNextItem: function(id, con, data){
			$('<input id="'+id+'" type="checkbox" data-type="subNext"/>').val(data[this.$vKey] === 0 && '0' || data[this.$vKey] || '').appendTo(con);
			$('<label for="'+id+'"/>').attr('title', LANG(data[this.$nKey])).text(LANG(data[this.$nKey])).appendTo(con);
			con.addClass('text-truncate');
		},
		eventToggleSub: function(evt, elm){
			// 有区级的时候，点击市区，全选区级
			this.eventToggleItem(evt, elm);

			// 有区级的时候，更新市级的count；没有区级的时候，更新省级的count;
			this.updateCount($(elm));

			// 更新zone的check
			this.updateZoneCheck($(elm).parents('.M-commonNewSLCZoneBody'));
		},
		eventToggleSubNext: function(evt, elm){
			// 复用sub点击函数
			this.eventToggleSub(evt, elm);

			// 区级点击的时候，也要更新省级的count
			this.updateCount($(elm).parent().parent().parent().find('>.M-commonNewSLCItemHead>input'));
		},
		// 更新计算
		updateCount: function(input){
			var parent;
			// 通过当前点击的checkbox找到上一个级别的count计算
			if($(input).parent().hasClass('M-commonNewSLCItemHead')){
				parent = $(input).parent().parent().parent().parent();
			}else{
				parent = $(input).parent().parent().parent();
			}

			var ul = parent.find('>.M-commonNewSLCSub'); // 子级的全部
			var total = ul.children().length;
			var check = 0;

			var checks = [];
			var lis = ul.children();
			$.each(lis, function(idx, li){
				if($(li).find('>input:checked').length){
					checks.push($(li));
				}else{
					if($(li).find('>.M-commonNewSLCItemHead>input:checked').length){
						checks.push($(li));
					}
				}
			});
			check = checks.length;

			if(check > 0 && check != total){
				parent.find('>.M-commonNewSLCSubCount').css('display', 'block').text(check + '/' + total);
			}else{
				parent.find('>.M-commonNewSLCSubCount').hide();
			}

			ul.prev().children('input').prop('checked', check > 0);
		},
		/**
		 * 设置选中的项目
		 * @param {Array} sels 选中的项目ID值
		 * @return {None} 无返回
		 */
		setData: function(sels){
			this.reset();
			if (!sels || !sels.length){
				return;
			}
			this.$selected = sels;

			var i,map = {};
			for (i=sels.length-1; i>=0; i--){
				map[sels[i]] = 1;
			}

			var dom, body = this.$doms.body;
			var doms = body.find('input[value!=""]');
			for (i=doms.length-1; i>=0; i--){
				dom = doms.eq(i);
				if (map[dom.val()]){
					dom.prop('checked', true);
					if(dom.attr('data-type') == 'subNext'){
						this.eventToggleSubNext(null, dom);
					}else{
						this.eventToggleSub(null, dom);
					}
				}
			}
		},
		/**
		 * 清空所有选择
		 * @return {None} 无返回
		 */
		reset: function(){
			var doms = this.$doms;
			doms.head.find('input').prop('checked', false);
			doms.body.find('input').prop('checked', false);
			doms.body.find('.M-commonNewSLCSubCount').hide();
			this.$selected = null;
		},
		/**
		 * 获取选中的区域数据
		 * @return {Array} 返回选中的区域ID数组
		 */
		getData: function(){
			var merge = !this.getConfig().getSubs;
			var ret = [];
			// 获取项目数据
			var input, body = this.$doms.body;
			var doms = body.find('.M-commonNewSLCItem');


			$.each(doms, function(idx, item){
				var input;
				var subs = $(item).find('>.M-commonNewSLCSub .hasSub');
				if(subs.length){
					var result = [];
					// 如果有区级，先处理区级
					$.each(subs, function(idx, sub){
						if(sub){
							sub = $(sub);
							var total = sub.find('>.M-commonNewSLCSub input');
							var check = total.filter(':checked');
							var input = sub.find('>.M-commonNewSLCItemHead > input');
							if(total.length > 0 && check.length == total.length && input.val() !== ''){
								result.push(input.val());
								if (merge){ check = false; }
							}
							if (check){
								for (var j=0; j<check.length; j++){
									input = check.eq(j);
									if (input.val() !== ''){
										ret.push(input.val());
									}
								}
							}
						}
					});
					// 处理市级
					if(result.length){
						if(result.length == subs.length){
							input = $(item).find('>.M-commonNewSLCItemHead > input');
							if(input.val() !== ''){
								ret.push(input.val());
							}
						}else{
							ret = ret.concat(result);
						}
					}
				}
				else{
					// 处理省级
					var total = $(item).find('.M-commonNewSLCSub input');
					var check = total.filter(':checked');
					input = $(item).find('.M-commonNewSLCItemHead > input');
					if (total.length > 0 && check.length == total.length && input.val() !== ''){
						ret.push(input.val());
						if (merge){ check = false; }
					}
					if (check){
						for (var k=0; k<check.length; k++){
							input = check.eq(k);
							if (input.val()){
								ret.push(input.val());
							}
						}
					}
				}

				input = $(item).find('>input').filter(':checked');
				if(input.length && input.val() !== ''){
					ret.push(input.val());
				}

			});

			// 获取分区数据
			doms = body.find('.M-commonNewSLCZoneHead > input[value!=""]');
			for (var i=0; i<doms.length; i++){
				input = doms.eq(i);
				if (input.prop('checked')){
					ret.push(input.val());
				}
			}

			this.$selected = ret;
			return ret;
		}
	});
	exports.subLevelCheckbox = SubLevelCheckbox;

	var listCache = null;

	var Base = SubLevelCheckbox.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'hasSearch': true
			});
			this.Super('init', arguments);
			if (listCache){
				this.setList(listCache);

			}else {
				pubjs.mc.send('category/zone', {ChannelId: 168, Layer: 5}, this.onData.bind(this));
				//pubjs.data.get(ROOT('config/country.json'), this);
			}

			// 添加五个辅助按钮
			var buttonsDiv = $('<div class="M-commonNewSLCButtons"></div>');
			this.getDOM().prepend(buttonsDiv);
			var buttons = [
				{'class': 'selectFirstLine', 'onFunc': 'eventSelectFirstLine', 'text': LANG('一线城市')},
				{'class': 'selectSecondLine', 'onFunc': 'eventSelectSecondLine', 'text': LANG('二线城市')},
				{'class': 'selectThirdLine', 'onFunc': 'eventSelectThirdLine', 'text': LANG('三线城市')},
				{'class': 'selectInverse', 'onFunc': 'eventSelectInverse', 'text': LANG('反选')},
				{'class': 'clearAll', 'onFunc': 'eventClearAll', 'text': LANG('清空')}
			]
			var i, len
			for(i = 0, len = buttons.length; i < len; i++) {
				var val = buttons[i];
				// 添加辅助按钮标签
				$('<a class="' + val['class'] + '">' + val['text']  + '</a>').appendTo(buttonsDiv);
				// 添加事件
				this.uiProxy(this.getDOM(), '.' + val['class'], 'click', val['onFunc']);
			}

			if(this.getConfig().hasSearch){
				var searchDiv = $([
					'<div class="M-commonNewSLCSearch">',
						'<input type="text" class="searchInput" placeholder="'+LANG('请输入搜索名称')+'"/>',
						'<em class="do"/>',
						'<em class="undo"/>',
					'</div>'
				].join('')).prependTo(buttonsDiv);
				this.$searchInput = searchDiv.find('input');
				this.uiBind(searchDiv.find('input'), 'keyup', 'input', 'eventSearch');
				this.uiBind(searchDiv.find('.do'), 'click', 'eventSearch');
				this.uiBind(searchDiv.find('.undo'), 'click', 'cancel', 'eventSearch');
			}

			// 特殊城市数据
			this.$cityData = {
				// 一线城市
				'firstLine': ["10761_10782_0", "10761_10783_0", "10761_10789_47667", "10761_10789_16496", "10761_10787_0"],
				// 二线城市
				'secondLine': ["10761_10787_69468", "10761_10765_37634", "10761_10773_104007", "10761_10779_103995",
					"10761_12768_104038", "10761_10786_33489", "10761_11573_36785", "10761_10763_68433", "10761_10785_33494",
					"10761_10779_104009", "10761_10763_54096", "10761_10785_59532", "10761_10769_104006", "10761_10766_25160",
					"10761_10768_104085", "10761_10770_104026", "10761_10772_104044", "10761_10768_104084", "10761_10774_104317",
					"10761_10788_104002", "10761_10776_104058", "10761_10765_33383", "10761_10765_104040", "10761_10764_104083",
					"10761_10778_104137", "10761_10777_104110", "10761_10762_104129", "10761_10784_104063", "10761_10771_232179",
					"10761_10780_104622", "10761_10789_57963", "10761_10789_59143", "10761_10771_104301", "10761_10785_104047",
					"10761_10768_104130", "10761_10780_234748"],
				// 三线城市
				'thirdLine': ["10761_10781_104211","10761_10767_104339","10761_10770_104113","10761_10765_104089",
					"10761_10765_104055","10761_10765_104013","10761_10785_104135","10761_10785_104191","10761_10763_104123",
					"10761_10763_104116","10761_10763_333580","10761_10769_239044","10761_10779_104062","10761_10789_232153",
					"10761_10789_104157","10761_10789_104057","10761_10766_104060","10761_10777_104069","10761_10775_104132",
					"10761_10771_104092","10761_10771_104250","10761_10771_104190","10761_10771_105534","10761_10785_104079",
					"10761_10785_104204","10761_10785_104374","10761_10785_104356","10761_10785_104303","10761_10785_104308",
					"10761_10785_104076","10761_10763_104121","10761_10763_104118","10761_10763_104117","10761_10765_104309",
					"10761_10765_104039","10761_10765_104144","10761_10765_104046","10761_10777_104056","10761_10789_104221",
					"10761_10789_104068","10761_10789_104220","10761_10789_104146","10761_10772_104136","10761_10772_104246",
					"10761_10772_104203","10761_12768_104532","10761_10773_104148","10761_10770_104042","10761_10770_104271",
					"10761_10770_104273","10761_10764_104143","10761_10764_104294","10761_10762_104128","10761_10786_24848",
					"10761_10769_104259","10761_10769_104257","10761_10779_104410","10761_10779_104073","10761_10779_104507",
					"10761_10779_104074","10761_10779_104077","10761_10779_104075","10761_10771_104344","10761_10771_104254",
					"10761_10771_104609","10761_10784_104516","10761_12768_104535","10761_10776_253019","10761_10774_104235",
					"10761_10770_104195","10761_10770_104253","10761_10770_104070","10761_10770_104091","10761_10770_104109",
					"10761_10785_104358","10761_10785_104142","10761_10785_104261","10761_10762_104156","10761_10762_104180",
					"10761_10762_104335","10761_10765_104188","10761_10765_234026","10761_10763_106316","10761_10763_104283",
					"10761_10773_104487","10761_10762_104177","10761_10764_104641","10761_10764_104587","10761_10772_104081",
					"10761_10772_104193","10761_10772_104262","10761_10768_104119","10761_10789_104403","10761_10789_333558",
					"10761_10789_104175","10761_10789_104214","10761_10777_104342","10761_10777_105302","10761_10786_104408",
					"10761_10786_104371","10761_10778_67317","10761_10788_104524"]
			}
		},
		onData: function(err, data){
			if (err){
				pubjs.alert(err.message);
				return false;
			}

			var key = this.getConfig('key');

			listCache = data;
			this.setList(listCache);

			// 所有可选择的城市列表，用于反选
			var selectableCitys = [];
			// 此方法用于获得所有具体城市（不包括省份、地区）的列表
			// 参数为城市数据的顶层对象
			// 注意方法内会递归调用
			function findCity(citys) {
				var city = null;
				for(var i = 0, len = citys.length; i < len; i++) {
				  city = citys[i];
				  if (city[key] && city[key].length > 0) {
						findCity(city[key]);
					} else {
					  // 没有child或child长度为零，该选项为可选择
					  selectableCitys.push(city.value)
				  }
				}
			}
			findCity(listCache);
			this.$selectableCitys = selectableCitys;

			this.fire('dataLoadEnd');

		},
		getDesc: function(){
			var checkeds = this.getDOM().find('input').filter(':checked');
			var desc = {};
			var result = [];
			var data = this.getData();
			$.each(checkeds, function(idx, item){
				var id = $(item).val();
				var text = $(item).next().text();
				desc[id] = text;
			});

			// 只返回id组对应的地区名称
			util.each(data, function(item){
				if(item){
					if(desc[item]){
						result.push(desc[item]);
					}
				}
			});
			return result;
		},
		eventSearch: function(evt, elm){
			var self = this;
			var el = self.getDOM();
			var c = self.getConfig();
			var val;
			var labels;
			var tmp;

			if(evt.data == 'input' && evt.keyCode != 13){
				return;
			}

			// 先全部清除高亮
			el.find('.M-commonNewSLCZoneBody label').removeClass('highlight');

			if(c.hasSearch){
				if(evt.data == 'cancel'){
					self.$searchInput.val('');
					$(elm).hide();
				}else{
					val = util.trim(self.$searchInput.val() || '');
					$(elm).siblings('em').show();
				}

				labels = el.find('.M-commonNewSLCZoneBody label[title*="'+ val +'"]').addClass('highlight');

				if(!labels.length || !val){
					el.find('.M-commonNewSLCZoneBody label').removeClass('highlight');
				}else{
					// 一直查找到省级，都显示高亮
					// $.each(labels.parents(), function(idx, dom){
					// 	if($(dom).find('>.M-commonNewSLCItemHead').length){
					// 		$(dom).find('>.M-commonNewSLCItemHead>label').addClass('highlight');
					// 	}
					// });
					// 笨的方法
					tmp = labels.parent().parent().parent().find('>.M-commonNewSLCItemHead label').addClass('highlight');
					tmp.parent().parent().parent().parent().find('>.M-commonNewSLCItemHead label').addClass('highlight');
				}
			}
		},
		// 选择一线城市
		eventSelectFirstLine: function(ev, elm) {
			var newSelected = this._merageArray(this.$cityData.firstLine, this.getSelectedSubCity());
			this.setData(newSelected);
		},
		// 选择二线城市
		eventSelectSecondLine: function(ev, elm) {
			var newSelected = this._merageArray(this.$cityData.secondLine, this.getSelectedSubCity());
			this.setData(newSelected);
		},
		// 选择三线城市
		eventSelectThirdLine: function(ev, elm) {
			var newSelected = this._merageArray(this.$cityData.thirdLine, this.getSelectedSubCity());
			this.setData(newSelected);
		},
		// 反选
		eventSelectInverse: function(ev, elm) {
			// 得到没选择的城市
			var inverseCitys = _complementArray(this.$selectableCitys, this.getSelectedSubCity())
			this.setData(inverseCitys);
		},
		// 清空选择
		eventClearAll: function(ev, elm) {
			this.setData([]);
		},
		// 取得已经选择的城市（不包括省份和地区，包括其他）
		getSelectedSubCity: function() {
			var self = this;
			this.$selectedSubCity = [];
			this.$doms.body.find('input:checkbox[checked="checked"]').each(function() {
				var el = $(this);
				var val = el.val();
				// “其他”选项使用的是数字0而非字符串，需先转换
				if (val === "0") {
					val = 0;
				}
				if (self.$selectableCitys.indexOf(val) >= 0) {
					self.$selectedSubCity.push(val)
				}
			})
			return this.$selectedSubCity;
		},
		// 此方法用于合并两个数组，但不添加重复的元素
		// 考虑将该方法添加到util
		_merageArray: function(arr1, arr2) {
			var newArr = arr1.slice(0);
			arr2.filter(function(e) {
				if (arr1.indexOf(e) < 0) {
					newArr.push(e)
				}
			})
			return newArr;
		}
	});
	exports.base = Base;

});